//
//  MainShoppingView.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/4/13.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "MainShoppingView.h"

@interface MainShoppingView()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic,strong) NSMutableArray *dataSourceArr;

@property (nonatomic,strong) UICollectionView *collectionV;

@end

@implementation MainShoppingView

-(id)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        
        [self initUI];
    }
    return self;
}

-(void)initUI{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(ScreenWidth/2-10, (ScreenWidth/2-10)*1.2);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    
    self.collectionV = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
    self.collectionV.delegate = self;
    self.collectionV.dataSource = self;
    self.collectionV.backgroundColor = MainBackColor;
    [self addSubview:self.collectionV];
    [self.collectionV registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
}
#pragma mark - UICollectionViewDelegate
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    return CGSizeMake((ScreenWidth/2-10), (ScreenWidth/2-10)*1.2);
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 40;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * CellIdentifier = @"cell";
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    
//    cell.backgroundColor = RGB(3*indexPath.row + 50, 5*indexPath.row, 7*indexPath.row);
    
    cell.backgroundColor = RGB(arc4random_uniform(255), arc4random_uniform(255), arc4random_uniform(255));
    
    return cell;
}




@end
